import { craeteEffect, effectTypes } from './helper'

/** 
 * 提供一个函数，用于产生delay effect 
 * @export
 * @param {number} duration 延迟时间
 */
export function delay2(duration) {
    return craeteEffect(effectTypes.DELAY2, { duration })
}

/**
 * 处理delay effect 
 * @export
 * @param {*} env
 * @param {*} effect
 * @param {*} next
 */
export function runDelay2Effect(env, effect, next) {
    const { payload: { duration } } = effect
    const result = new Promise((resolve) => setTimeout(resolve, duration))
    result.then(r => next(r))
}